home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / ici / ici.cpi / tst-oner.ici < prev    next >
Text File  |  1994-10-27  |  984b  |  69 lines

  1. static x;
  2.  
  3. try
  4.     x = 1;
  5. onerror
  6.     fail("failed when should not have");
  7.  
  8. x = 0;
  9. try
  10. {
  11.     x = 1;
  12.     fail("should happen");
  13.     x = 2;
  14. }
  15. onerror
  16. {
  17.     if (error != "should happen")
  18.     fail("wrong error string");
  19.     if (x != 1)
  20.     fail("wrong flow of control for error (no. 1)");
  21.     x = 3;
  22. }
  23. if (x != 3)
  24.     fail("wrong flow of control for error (no. 2)");
  25.  
  26. static
  27. func1(a)
  28. {
  29.     try
  30.     {
  31.     try
  32.         return 1 / a;
  33.     onerror
  34.         fail(error);
  35.     }
  36.     onerror
  37.     return 0;
  38.     return 2;
  39. }
  40.  
  41. if (func1(1) != 1)
  42.     fail("nested onerror in function failed");
  43.  
  44. if (func1(0) != 0)
  45.     fail("failure in nested onerror failed");
  46.  
  47. static
  48. func2()
  49. {
  50.     auto    error;
  51.  
  52.     try
  53.     fail("failure");
  54.     onerror
  55.     return error;
  56.     return "no failure";
  57. }
  58.  
  59. error = "should not be effected";
  60. if (func2() != "failure")
  61.     fail("fail returned wrong string");
  62. if (error != "should not be effected")
  63. {
  64.     printf("error = %s\n", error);
  65.     fail("wrong scope in setting error");
  66. }
  67.  
  68. fail("deliberate failure");
  69.